<?php

/**
 * 前台 博文详情 模块 Controller
 * ============================================================================
 * TBlog TBlog博客系统　BY Tmac PHP MVC framework
 * $Author: zwt007 $  <zwttmac@qq.com>
 * $Id: article.php 156 2013-10-19 10:17:21Z zwt007 $
 * http://www.t-mac.org；
 */
class articleAction extends Action
{

    private $tmp_model;
    private $category_model;
    private $common_model;

    public function _init()
    {
        $this->tmp_model = Tmac::model('article');
        $this->category_model = Tmac::model('category');
        $this->common_model = Tmac::model('common');
        $this->config = $this->common_model->getCommon();
        //取导航条的内容并缓存起来，缓存时间1天
        $cat_list = Tmac::getCache('cat_list', array($this->category_model, 'getCategoryList'), array(0), 86400);
        $array['config'] = $this->config;
        $array['cat_list'] = $cat_list;
        $this->assign($array);
    }

    public function index(){
        $aid = intval($this->getParam('id'));
        $separator = '&lt;--more--&gt;';
        $info = $this->tmp_model->getArticleInfo($aid);
        if (!$info) {
            $this->V('404');
            exit;
        }

        //判断有没有more的内容
        if (strpos($info['content'], $separator)) {
            $info['content'] = str_replace($separator, '<span id="more-'.$aid.'"></span>', $info['content']);
        }
        $info['tag_info'] = json_decode($info['tag_info'],true);

        //取category_info
        $catinfo = $this->category_model->getCategoryInfo($info['cat_id']);
        //广告位        
        $array['article_left_center'] = $this->common_model->ShowAD('article_left_center');
        
        $this->assign('info', $info);
        $this->assign('catinfo', $catinfo);
        $this->assign($array);
        $this->V('article');
    }

}